package com.mediastory.spsserver.app.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.mediastory.spsserver.app.dao.AppDao;
import com.mediastory.spsserver.app.domain.App;

/**
 * @author Jaewon Choi
 *
 */

@Repository
public class AppDaoImpl extends SqlSessionDaoSupport  implements AppDao {

	public AppDaoImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<App> SelectList(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer page = (Integer)condition.get("page");
		Integer maxnum = (Integer)condition.get("maxnum");
		
		List<App> result = null;
		if(page != null && maxnum != null){
			RowBounds rb = new RowBounds(page, maxnum);
			result = getSqlSession().selectList("App.selectList", condition, rb);
		}else{
			result = getSqlSession().selectList("App.selectList", condition);
		}
		
		return result;
	}
	
	@Override
	public Integer SelectListTotalCnt(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer result = getSqlSession().selectOne("App.selectListTotalCnt", condition);
		return result;
	}

	@Override
	public App select(Integer id) throws Exception {
		// TODO Auto-generated method stub
		App result = (App)(getSqlSession().selectOne("App.select", id)); 
		return result;
	}

	@Override
	public App insert(App app) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().insert("App.insert", app);
		return app;
	}

	@Override
	public App update(App app) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("App.update", app);
		return app;
	}

	@Override
	public int delete(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("App.delete", condition);
		return result;
	}

}
